-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(config-cli): Provide a cli for creating temporary server and dump screenshots. #2236
Conversation
packages/config-cli/README.md
Outdated
Create a temporary server from a config bundle file and dump the screenshots | ||
|
||
```bash | ||
./bin/bmc.js screenshot-server - config s3://..../config.json.gz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should just be a argument to screenshot
eg
./bin/bmc.js screenshot --config s3://.../config.json.gz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be good to separate to two different cli? I think this will make the cli logic not too complex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be pretty simiple logic ?
something like
if (this.config.value)
const host = await startServer()
return await screenshot(host);
}
return await screenshot(this.host.value)
they are both doing the same thing, screenshotting some host, so to me they are the same command
const port = 5000; | ||
const ServerUrl = `http://localhost:${port}`; | ||
const BasemapsServer = createServer(logger); | ||
BasemapsServer.listen(port, '0.0.0.0', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is async you should really await
for the server to start before starting chrome.
granted chrome startup is going to be way slower than the server but it could create issues if the server startup takes too long
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createServer()
is not async function? Do you want me to update to async?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like this
await new Promise(resolve => BaseampsServer.listen(port, '0.0.0.0', () => resolve()))
Config.setConfigProvider(mem); | ||
|
||
// Create a basemaps server. | ||
const port = 5000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this port should be a high random number, is there a npm package to find a unused port?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using random free port from 10000 to 11000 now.
|
||
async getTileSetId(tileSetId: string, tag: string): Promise<string> { | ||
if (tag === 'production') return tileSetId; | ||
async function getTileSetId(tileSetId: string, tag: string): Promise<string> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove these now.
if we are pointing at a bundled config there is not @tag
to worry about any more!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pr tag removed. We can just point a lambda function url as host to take screenshot for linz/basemaps-config
.
BasemapsServer = createServer(logger); | ||
|
||
if (BasemapsServer == null) throw new Error('Failed to Create server with the config File'); | ||
BasemapsServer.listen(port, '0.0.0.0', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not waiting for this to finish loading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I forget this. Just fixed.
packages/config-cli/README.md
Outdated
Dump the screenshots with config file | ||
|
||
```bash | ||
./bin/bmc.js screenshot - config s3://..../config.json.gz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--config ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good pick.
if (config != null) { | ||
const port = await getPort({ port: portNumbers(10000, 11000) }); | ||
host = `http://localhost:${port}`; | ||
const server = createServer(logger); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: why create a new var if we could just use BasemapsServer
another option would be const BasemapsServer = this.startServer(config)
which returns null | Server
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why if I pass the BasemapsServer
into the await new Promise<void>()
if always return type checking errors to say that BasemapsServer
could be undefined
even I have checked not null before. So I create a new var to pass it after.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah if you did this as a function that returned Promise<Server | null>
could be optimised out.
|
||
// Start server | ||
const server = createServer(logger); | ||
server.listen(port, '0.0.0.0', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this lost its promise again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I copy from the wrong place. Just fixed.
|
||
// Start server | ||
const server = createServer(logger); | ||
await new Promise<void>((resolve) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return new Promise<FastifyInstance>(r => {
r(server);
});
if (style) return styleIdTagId; | ||
return styleId; | ||
} | ||
async function startServer(host: string, port: number, config: string, logger: LogType): Promise<FastifyInstance> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is host passed in just to log it?
could generate host inside the function or log outside the function
|
||
let BasemapsServer: FastifyInstance | undefined = undefined; | ||
if (config != null) { | ||
const port = await getPort({ port: portNumbers(10000, 11000) }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just use any port?
No description provided.